from flask import Flask, request
from flask import Blueprint

import json

from fasttext_model import fasttext_model_01 as fm_01

fasttext_routes = Blueprint('fasttext_routes', __name__)


@fasttext_routes.route('/fasttext_01/v1', methods=['post'])
def fasttext_model_01():
    """fasttext 模型 V1"""
    if not request.data:  # 检测是否有数据
        return ''

    params = request.data.decode('utf-8', errors='ignore')
    input_params = json.loads(params)

    pred = fm_01.predict_probability(input_params)

    return str(pred)
